package com.cap2.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;

import java.io.IOException;

@Configuration
public class TypeFilter implements org.springframework.core.type.filter.TypeFilter {
    private ClassMetadata classMetadata;
    /**
     *
     * @param metadataReader        读取到当前正在扫描类的信息
     * @param metadataReaderFactory 可以获取到其他任何类信息
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
            //获取当前类注解的信息
            AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
            //获取当前正在扫描的类信息
            classMetadata = metadataReader.getClassMetadata();
            //获取当前类资源(类的路径)
            Resource resource = metadataReader.getResource();

            String className = classMetadata.getClassName();
            System.out.println("----->"+className);
            if(className.contains("Order")){//当类包含er字符, 则匹配成功,返回true
                return true;
            }
            return false;
    }
}
